package com.albd.utils;

import agj.hooks.BBinderListener;
import android.os.RemoteException;
import android.util.Log;

import com.kingsgame.register.RegisterEntry;
import com.mst.albd.IMyService;

public class VerifyUtil
{	
	private static boolean isCmd(int aCmd)
	{
		boolean vRet = false;
		//if(aCmd > SystemDef.EnumCmd.CMD_BASE.ordinal() && aCmd < SystemDef.EnumCmd.CMD_MAX.ordinal())
		//{
		//	vRet = true;
		//}
		return vRet;
	}

	public static boolean sendCmd(int aCmd, IMyService aService, String aProName)
	{
		boolean vRet = false;
		if(aService != null && isCmd(aCmd))
		{
			try
			{
				aService.upClient(aProName);
				vRet = true;
			}
			catch (RemoteException e)
			{
				e.printStackTrace();
			}			
		}
		return vRet;
	}	
	
	public static void upClient(){
		try {
			if(BBinderListener.mService == null){
				RegisterEntry.mListener.bindIMyService();
			}
			if(BBinderListener.mService != null){
				BBinderListener.mService.upClient("");
			}
			LogUtil.i("wmm", "BBinderListener.mService upClient called", true);
		} catch (RemoteException e) {
			e.printStackTrace();
			LogUtil.i("wmm", "BBinderListener.mService upClient exception " + e.getMessage(), true);
		}
	}
	
	@SuppressWarnings("finally") public static boolean queryAllowed(String aProName, int aPid, int aAction, String aParam1, String aParam2){
		boolean vRet = false;
		//TODO 如果服务不存在，bindservice
		if(!SystemUtil.isServiceRunning(RegisterEntry.sContext, "com.mst.albd.MyService")){
			RegisterEntry.mListener.bindIMyService();
		}
		try
		{
			if(BBinderListener.mService != null){
				vRet = BBinderListener.mService.queryAllowed(aProName, aPid, aAction, aParam1, aParam2);
			}
		}
		catch (RemoteException e)
		{
			e.printStackTrace();
		}
		finally{
			return vRet;
		}
	}
	
}
